package cn.lili.modules.order.order.client;

import cn.lili.common.vo.PageVO;
import cn.lili.modules.constant.ServiceConstant;
import cn.lili.modules.distribution.entity.vos.DistributionOrderSearchParams;
import cn.lili.modules.member.entity.dos.User;
import cn.lili.modules.order.fallback.OrderFallback;
import cn.lili.modules.order.order.entity.dos.Order;
import cn.lili.modules.order.order.entity.dos.OrderFlow;
import cn.lili.modules.order.order.entity.dto.OrderExportDTO;
import cn.lili.modules.order.order.entity.dto.OrderFlowDTO;
import cn.lili.modules.order.order.entity.dto.OrderSearchParams;
import cn.lili.modules.order.order.entity.vo.*;
import cn.lili.modules.system.entity.vo.Traces;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单服务client
 *
 * @author Chopper
 * @version v1.0 2021-11-08 09:52
 */
@FeignClient(path = "${server.servlet.context-path}", name = ServiceConstant.ORDER_SERVICE, contextId = "order", fallback = OrderFallback.class)
public interface OrderClient {

    /**
     * 订单编号查询
     *
     * @param sn 订单编号
     * @return 订单模型
     */
    @GetMapping("/feign/order/query/{sn}")
    Order getBySn(@PathVariable String sn);

    /**
     * 系统取消订单
     *
     * @param orderSn 订单编号
     * @param reason  错误原因
     */
    @GetMapping("/feign/order/system/cancel")
    void systemCancel(@RequestParam String orderSn, @RequestParam String reason);

    /**
     * 获取实际支付金额
     *
     * @param orderSn 订单编号
     * @return 支付金额
     */
    @GetMapping("/feign/order/query/{orderSn}/payment-total")
    Double getPaymentTotal(@PathVariable String orderSn);

    /**
     * 获取订单详情
     *
     * @param sn 订单编号
     * @return
     */
    @GetMapping("/feign/order/query/{sn}/detail-vo")
    OrderDetailVO queryDetail(@PathVariable String sn);

    /**
     * 根据交易sn，获取订单列表
     *
     * @param sn
     * @return
     */
    @GetMapping("/feign/order/query/{sn}/by-trade-sn")
    List<Order> getByTradeSn(@PathVariable String sn);


    @GetMapping("/feign/order/query/{sn}/by-parent-sn")
    List<Order> getByParentSn(@PathVariable String sn);

    /**
     * 订单信息
     *
     * @param orderSearchParams 查询参数
     * @return 订单信息
     */
    @PostMapping("/feign/order/query/list")
    List<Order> queryListByParams(@RequestBody OrderSearchParams orderSearchParams);

    /**
     * 根据促销查询订单
     *
     * @param orderPromotionType 订单类型
     * @param payStatus          支付状态
     * @param parentOrderSn      依赖订单编号
     * @param orderSn            订单编号
     * @return 订单信息
     */
    @GetMapping("/feign/order/query/promotions/list")
    List<Order> queryListByPromotion(@RequestParam String orderPromotionType, @RequestParam String payStatus, @RequestParam String parentOrderSn,
                                     @RequestParam String orderSn);

    /**
     * 根据促销查询订单
     *
     * @param orderPromotionType 订单类型
     * @param payStatus          支付状态
     * @param parentOrderSn      依赖订单编号
     * @param promotionId        促销id
     * @param skuId              skuId
     * @return 订单信息
     */
    @GetMapping("/feign/order/query/promotions/id/list")
    List<Order> queryListByPromotionId(@RequestParam String orderPromotionType, @RequestParam String payStatus, @RequestParam String parentOrderSn,
                                     @RequestParam String promotionId, @RequestParam String skuId);

    /**
     * 根据促销查询订单
     *
     * @param orderPromotionType 订单类型
     * @param payStatus          支付状态
     * @param parentOrderSn      依赖订单编号
     * @param orderSn            订单编号
     * @return 订单信息
     */
    @GetMapping("/feign/order/query/promotions/count")
    long queryCountByPromotion(@RequestParam String orderPromotionType, @RequestParam String payStatus, @RequestParam String parentOrderSn,
                               @RequestParam String orderSn);

    /**
     * 检查是否开始虚拟成团
     *
     * @param pintuanId   拼团活动id
     * @param requiredNum 成团人数
     * @param fictitious  是否开启成团
     * @return 是否成功
     */
    @GetMapping("/feign/order/fictitious/pintuan/{pintuanId}")
    boolean checkFictitiousOrder(@PathVariable String pintuanId, @RequestParam Integer requiredNum, @RequestParam Boolean fictitious);

    @PostMapping("/feign/order/fictitious/save")
    void save(@RequestBody Order order);

    @GetMapping("/feign/order/{orderSn}/fictitious/afterOrderConfirm")
    void afterOrderConfirm(@PathVariable String orderSn);

    /**
     * 自动成团订单处理
     *
     * @param pintuanId     拼团活动id
     * @param parentOrderSn 拼团订单sn
     */
    @GetMapping("/feign/order/agglomerate/pintuan/{pintuanId}")
    void agglomeratePintuanOrder(@PathVariable String pintuanId, @RequestParam String parentOrderSn);

    @PutMapping("/feign/order/fictitious/update")
    void update(@RequestBody Order order);

    @PostMapping("/feign/order/fictitious/getOne")
    Order getOne(@RequestBody Order order);

    /**
     * 查询订单列表分页
     *
     * @param orderSearchParams
     * @return
     */
    @PostMapping("/feign/order/fictitious/queryByParams")
    Page<OrderSimpleVO> queryByParams(@RequestBody OrderSearchParams orderSearchParams);

    /**
     * 分销订单查询
     * @param distributionOrderSearchParams
     * @return
     */
    @PostMapping("/feign/order/fictitious/distributionQuery")
    Page<OrderSimpleVO> distributionQuery(@RequestParam DistributionOrderSearchParams distributionOrderSearchParams);

    /**
     * 订单发货
     *
     * @param orderSn
     * @param logisticsNo
     * @param logisticsId
     * @return
     */
    @PostMapping("/feign/order/fictitious/delivery")
    Order delivery(@RequestParam String orderSn, @RequestParam String logisticsNo, @RequestParam String logisticsId);

    /**
     * 取消订单
     *
     * @param orderSn
     * @param reason
     * @return
     */
    @PostMapping("/feign/order/cancel")
    Order cancel(@RequestParam String orderSn, @RequestParam String reason);

    /**
     * 下载待发货的订单列表
     *
     * @param response
     * @param logisticsName
     */
    @PostMapping("/feign/order/getBatchDeliverList")
    void getBatchDeliverList(@RequestParam HttpServletResponse response, @RequestParam List<String> logisticsName);

    /**
     * 上传文件进行订单批量发货
     *
     * @param files
     */
    @PostMapping("/feign/order/batchDeliver")
    void batchDeliver(@RequestBody MultipartFile files);

    /**
     * 查询订单导出列表
     *
     * @param orderSearchParams
     * @return
     */
    @PostMapping("/feign/order/queryExportOrder")
    List<OrderExportDTO> queryExportOrder(@RequestBody OrderSearchParams orderSearchParams);

    /**
     * 获取物流踪迹
     *
     * @param orderSn
     * @return
     */
    @PostMapping("/feign/order/getTraces")
    Traces getTraces(@RequestParam String orderSn);

    /**
     * 供应商订单统计
     *
     * @param supplierId
     * @return
     */
    @PostMapping("/feign/order/pendingPaymentOrderNum")
    Map<String, Long> pendingPaymentOrderNum(@RequestParam String supplierId);

    /**
     * 订单每日任务
     */
    @PostMapping("/feign/order/everyDayTask")
    void everyDayTask();

    /**
     * 获取订单流水列表
     * @param orderSn
     * @return
     */
    @PostMapping("/feign/order/orderFlowList")
    List<OrderFlow> orderFlowList(@RequestParam String orderSn);

    @GetMapping("/getSumPrice")
    Map<String, Object> getSumPrice();

    /**
     * 是否购买过盲盒：没有则是盲盒新用户。
     * @param buyerId 订单购买用户
     * @return 数量
     */
    @GetMapping("/feign/getCountByBuyerId")
    Long getCountByBuyerId(@RequestParam String buyerId);


    /**
     * 获取当前用户的消费金额
     * @param uid 用户id
     * @return 消费金额
     */
    @GetMapping("/feign/getMoneyByUid")
    Double getMoneyByUid(@RequestParam String uid);

    /**
     * 获取当前用户的支付金额
     * @param uid 用户id
     * @return 支付金额
     */
    @GetMapping("/feign/getShopkeeperMoneyByUid")
    Double getShopkeeperMoneyByUid(@RequestParam String uid);

    /**
     * 查询店主列表直推业绩
     * @return
     */
    @PostMapping("/feign/selectSubUserFlowPrice")
    Map<String, OrderFlow> selectSubUserFlowPrice(@RequestBody Map<String, List<String>> map);


    /**
     * 计算团队每位成员本月的金额
     *
     * @param userIdList 用户ID
     * @return 每位成员本月的金额
     */
    @PostMapping("/feign/computeMoney")
    List<OrderFlow> computeMoney(@RequestBody List<String> userIdList);

    /**
     * 根据用户id查找订单数
     * @param userIdList
     * @return
     */
    @GetMapping("/feign/selectCountOrderByUserIds")
    Map<String, Integer> selectCountOrderByUserIds(@RequestParam List<String> userIdList,@RequestParam String parentId);

    /**
     * 根据用户id查找本月消费数
     * @param userIdList 用户第
     */
    @PostMapping("/feign/selectCurrentConsumptionByUserIds")
    Map<String, Double> selectCurrentConsumptionByUserIds(@RequestBody List<String> userIdList,@RequestParam String parentId);

    /**
     * 根据用户id查找累计消费数
     * @param userIdList 用户第
     */
    @PostMapping("/feign/selectCumulativeConsumptionByUserIds")
    Map<String, Double> selectCumulativeConsumptionByUserIds(@RequestBody List<String> userIdList,@RequestParam String parentId);

    /**
     * 根据工会地区查询本月工会经费
     * @param areaId
     * @return
     */
    @GetMapping("/feign/getMonthUnionGreenScoreByAreaId")
    Double getMonthUnionGreenScoreByAreaId (@RequestParam String areaId);


    /**
     * 工会的今日首单，查询工会所在区域的首笔订单
     * @param province 省份
     * @param city 城市
     * @return
     */
    @GetMapping("/feign/todayOrderForUnion")
    OrderVO todayOrderForUnion(@RequestParam String province, @RequestParam String city);


    @GetMapping("/feign/todayOrderForUnionV2")
    OrderVO todayOrderForUnionV2(@RequestParam List<String> buyerIdList);

    /**
     * 工会今日最新N笔订单
     * @param buyerIdList 工会成员ID
     * @param pageNo
     * @param pageSize
     * @return
     */
    @PostMapping("/feign/getOrderForUnionByPageV2")
    Page<OrderVO> getOrderForUnionByPageV2(@RequestParam List<String> buyerIdList,
                                    @RequestParam Integer pageNo,
                                    @RequestParam Integer pageSize);





    /**
     * 获取工会成员本月业绩数据
     * @return
     */
    @PostMapping("/feign/getCurrentMonthByUnionMember")
    Page<OrderFlowDTO> getCurrentMonthByUnionMember (@RequestBody UnionOrderParams params);

    /**
     * 根据工会成员统计本月已结算金额、待结算金额、退单金额
     * @return
     */
    @PostMapping("/feign/getCurrentMonthStatisticsByMember")
    PerformanceDetailVO getCurrentMonthStatisticsByMember (@RequestBody UnionOrderParams params);

    /**
     * 获取工会成员本月业绩数据
     * @return
     */
    @PostMapping("/feign/getLastMonthByUnionMember")
    Page<OrderFlowDTO> getLastMonthByUnionMember (@RequestBody UnionOrderParams params);

    /**
     * 根据工会成员统计上月已结算金额、待结算金额、退单金额
     * @return
     */
    @PostMapping("/feign/getLastMonthStatisticsByMember")
    PerformanceDetailVO getLastMonthStatisticsByMember (@RequestBody UnionOrderParams params);

    /**
     * 获取工会业绩数据
     * @return
     */
    @PostMapping("/feign/getUnionMoneyDetail")
    Page<OrderFlow> getUnionMoneyDetail (@RequestBody UnionOrderParams params);

    /**
     * 获取工会经费数据
     * @return
     */
    @PostMapping("/feign/getUnionMoneyStatisticsDetail")
    PerformanceDetailVO getUnionMoneyStatisticsDetail (@RequestBody UnionOrderParams params);

    /**
     * 获取工会本月分销订单数量、已完成订单数量、未完成订单数量、已退单数量
     * @return
     */
    @GetMapping("/feign/getCurrentMonthUnionOrderCountByUnion")
    PerformanceDetailVO getCurrentMonthUnionOrderCountByUnion (@RequestParam String areaId);

    /**
     * 获取工会上月分销订单数量、已完成订单数量、未完成订单数量、已退单数量
     * @return
     */
    @GetMapping("/feign/getLastMonthUnionOrderByUnion")
    PerformanceDetailVO getLastMonthUnionOrderByUnion (@RequestParam String areaId);

    @PostMapping("/feign/executeCityDistributionLastMonthOrder")
    @ApiOperation("定时任务:店主升级城主")
    void executeCityDistributionLastMonthOrder();

    @PostMapping("/feign/executeCityDistributionComissLastMonthOrder")
    @ApiOperation("定时任务:城主佣金结算发放")
    void executeCityDistributionComissLastMonthOrder();

    /**
     * 查询工会成员本月业绩
     * @param memberId
     * @return
     */
    @GetMapping("/feign/getCurrentMonthMoneyByMemberId")
    Double getCurrentMonthMoneyByMemberId (@RequestParam String memberId);

    /**
     * 查询工会成员上月业绩
     * @param memberId
     * @return
     */
    @GetMapping("/feign/getLastMonthMoneyByMemberId")
    Double getLastMonthMoneyByMemberId (@RequestParam String memberId);

    @PostMapping("/feign/executeUnionGreenScoreLastMonthOrder")
    @ApiOperation("定时任务:工会佣金结算发放")
    void executeUnionGreenScoreLastMonthOrder();

    @PostMapping("/feign/getUnionCommissByMonth")
    Page<UnionMonthFundsVO> getUnionCommissByMonth(@RequestBody UnionOrderParams params);


    @GetMapping("/feign/updateProfitSharingOrderFlow")
    boolean updateProfitSharingOrderFlow(@RequestParam String orderSn);

    /**
     * 添加失败原因
     * @param orderSn 订单号
     * @param error 失败原因
     * @return 是否成功
     */
    @GetMapping("/feign/addOrderFlowProfitSharing")
    boolean addOrderFlowProfitSharing(@RequestParam String orderSn,@RequestParam String error);

    /**
     * 订单完成
     * @return
     */
    @GetMapping("/feign/order/fictitious/complete")
    Boolean complete(@RequestParam String orderNo);

}
